import 'package:flutter/material.dart';
import 'package:flutterdemo/0demo/ui/overlay_manager/overlay_manager_queue.dart';

class OverlayQueueTestPage extends StatefulWidget {
  const OverlayQueueTestPage({Key key}) : super(key: key);

  @override
  State<OverlayQueueTestPage> createState() => _OverlayQueueTestPageState();
}

class _OverlayQueueTestPageState extends State<OverlayQueueTestPage> {
  @override
  void initState() {
    // listen overlay queue show and dismiss
    overlayManagerQueue.addListenShowOrDismiss(_listen);
    super.initState();
  }

  @override
  void dispose() {
    // remove listen
    overlayManagerQueue.removeListenShowOrDismiss(_listen);
    super.dispose();
  }

  void _listen(OverlayVO overlay) {
    print("show or dismiss: ${overlay.toString()}");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("test overlay queue"),
      ),
      body: Align(
        alignment: Alignment.center,
        child: MaterialButton(
          onPressed: () {
            _show(context);
          },
          child: Text("show"),
        ),
      ),
    );
  }

  void _show(BuildContext context) {
    for (int i = 0; i < 3; i++) {
      Widget content = Align(
        alignment: Alignment.bottomCenter,
        child: Material(
          child: Container(
            height: 200,
            width: 200,
            alignment: Alignment.center,
            color: Colors.blue.withOpacity(0.4),
            child: Text("overlay$i"),
          ),
        ),
      );
      final vo = overlayManagerQueue.generateOverlayVO(content, context);
      overlayManagerQueue.add2show(vo);
    }
  }
}
